home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / openoffice / program / officehelper.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-29  |  2KB  |  65 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. import os
  5. import random
  6. from sys import platform
  7. from time import sleep
  8. import uno
  9. from com.sun.star.connection import NoConnectException
  10. from com.sun.star.uno import Exception as UnoException
  11.  
  12. class BootstrapException(UnoException):
  13.     pass
  14.  
  15.  
  16. def bootstrap():
  17.     '''Bootstrap OOo and PyUNO Runtime.
  18.     The soffice process is started opening a named pipe of random name, then the local context is used
  19. \tto access the pipe. This function directly returns the remote component context, from whereon you can
  20. \tget the ServiceManager by calling getServiceManager() on the returned object.
  21. \t'''
  22.     
  23.     try:
  24.         sOffice = os.path.join(os.path.dirname(__file__), 'soffice')
  25.         if platform.startswith('win'):
  26.             sOffice += '.exe'
  27.         
  28.         random.seed()
  29.         sPipeName = 'uno' + str(random.random())[2:]
  30.         cmdArray = (sOffice, '-nologo', '-nodefault', ''.join([
  31.             '-accept=pipe,name=',
  32.             sPipeName,
  33.             ';urp;']))
  34.         os.spawnv(os.P_NOWAIT, sOffice, cmdArray)
  35.         xLocalContext = uno.getComponentContext()
  36.         resolver = xLocalContext.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', xLocalContext)
  37.         sConnect = ''.join([
  38.             'uno:pipe,name=',
  39.             sPipeName,
  40.             ';urp;StarOffice.ComponentContext'])
  41.         nLoop = 20
  42.         while True:
  43.             
  44.             try:
  45.                 xContext = resolver.resolve(sConnect)
  46.             continue
  47.             except NoConnectException:
  48.                 nLoop -= 1
  49.                 if nLoop <= 0:
  50.                     raise BootstrapException('Cannot connect to soffice server.', None)
  51.                 
  52.                 sleep(0.5)
  53.                 continue
  54.             
  55.  
  56.             None<EXCEPTION MATCH>NoConnectException
  57.     except BootstrapException:
  58.         raise 
  59.     except Exception:
  60.         e = None
  61.         raise BootstrapException('Caught exception ' + str(e), None)
  62.  
  63.     return xContext
  64.  
  65.